﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.IO;

namespace WebServiceStart
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>

    [WebService(Namespace = "http://daoto.net/dotnet/ws/ExampleWS")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {
        //private string pathDir = "d:\\downloads\\";

        public struct ClientData
        {
            public String Name;
            public int ID;
        }


        [WebMethod(Description="Returns list of objects in directory ")]
        public string[] Dir(string pathDir)
        {
            string[] files = Directory.GetFiles(pathDir);
            for (int i = 0; i < files.Length; i++)
                files[i] = files[i].Replace(pathDir, "");

            string[] directories = Directory.GetDirectories(pathDir);
            for (int i = 0; i < directories.Length; i++)
                directories[i] = directories[i].Replace(pathDir, "");

            return (String.Join("|", files) + String.Join("|", directories)).Split('|');
        }

        [WebMethod(CacheDuration = 30,
         Description = "Returns an array of Clients.")]
        public ClientData[] GetClientData(int Number)
        {
            ClientData[] Clients = null;

            if (Number > 0 && Number <= 10)
            {
                Clients = new ClientData[Number];
                for (int i = 0; i < Number; i++)
                {
                    Clients[i].Name = "Client " + i.ToString();
                    Clients[i].ID = i;
                }
            }
            return Clients;
        }
    }
}
